package com.wq.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private Long current;
    private Long size;
    private Long total;
    private List<T> data;
    private String msg;
    private int errCode;
    private boolean success;

    public static <T> PageResult<T> success(IPage<T>  page) {
      PageResult<T> pageResult = new PageResult<>();
      pageResult.setData(page.getRecords());
      pageResult.setCurrent(page.getCurrent());
      pageResult.setSize(page.getSize());
      pageResult.setTotal(page.getTotal());
      pageResult.setSuccess(true);
      return pageResult;
    }
    public static <T> PageResult<T> error(String msg) {
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setMsg(msg);
        pageResult.setSuccess(false);
        return pageResult;
    }

}
